package org.smart.access.model;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * CREATE TABLE house (
 *     id INTEGER PRIMARY KEY,                          -- COMMENT '房屋ID'
 *     building TEXT NOT NULL,                          -- COMMENT '楼栋'
 *     room TEXT NOT NULL,                              -- COMMENT '房间号'
 *     version INTEGER NOT NULL DEFAULT 0,
 *     create_time TEXT NOT NULL DEFAULT (datetime('now')),  -- 对应 CURRENT_TIMESTAMP
 *     update_time TEXT NOT NULL DEFAULT (datetime('now')),  -- ON UPDATE 由应用层处理
 *     deleted INTEGER NOT NULL DEFAULT 0               -- COMMENT '逻辑删除'
 *     -- COMMENT '房屋表'
 * );
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("house")
public class House {
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;
    private String building;
    private String room;
    @Version
    private Integer version;
    @TableField(condition = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    @TableField(condition = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    @TableLogic
    private Integer deleted;
}
